/*
 * @Author: nengwu 409791297@qq.com
 * @Date: 2020-06-29 23:27:33
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-08-15 21:52:00
 * @description:
 */

import React, { useEffect, useState } from 'react'
import { FlatList, SafeAreaView } from 'react-native'
import NewsItem from '@/components/NewsItem'
import EmptyList from '@/components/EmptyList'
import styles from './styles'

const History = props => {
  const [historyList, setHistoryList] = useState([])

  useEffect(() => {
    global.storage.getAllDataForKey('historyList').then(list => {
      setHistoryList(list)
      console.log('getAllDataForKey:----------->', list)
    })
  }, [])

  const _renderItem = ({ item }) => (
    <NewsItem
      id={item.id}
      title={item.title}
      coverImgs={item.coverImgs}
      type={item.type}
      topping={item.topping}
    />
  )

  return (
    <>
      <SafeAreaView style={styles.wrap}>
        <FlatList
          data={historyList}
          renderItem={_renderItem}
          keyExtractor={item => item.id + item.title}
          ListEmptyComponent={<EmptyList />}
        />
      </SafeAreaView>
    </>
  )
}

export default History
